SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TerminateLatestCOI]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[TerminateLatestCOI]
GO

  
/***************************************************************************  
* Name:   TerminateLatestCOI  
* Purpose:  Insert/Update a COI  
*  
* PARAMETERS  
* Name     Description       
* -------------    -----------------------------------------------------------  
* @admPersonId    user's person id  
***************************************************************************/  
CREATE PROCEDURE [dbo].[TerminateLatestCOI] (  
  
@admPersonId  INT
 
)  
  
AS  
  
BEGIN  
  

    
  UPDATE ConflictOfInterest  
  SET  
   LastModified = GetDate(),  
   Status = 'COISTATUS_TERMINATED'
  WHERE [AdmPersonId] = @admPersonId
	AND Status in ('COISTATUS_START', 'COISTATUS_INPROGRESS')  
    
  IF @@ERROR <> 0 GOTO ERROR_HANDLER  
  
  RETURN  
    

  
 ERROR_HANDLER:  
  IF @@ERROR <> 0   
  BEGIN  
   RAISERROR('Unable to Terminate COI', 16, 1)  
   RETURN  
  END  
END  
  
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

